package com.wcfsy.wechat.wx.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wcfsy.wechat.wx.entity.Coupon;
import com.wcfsy.wechat.wx.pagination.IPage;
import com.wcfsy.wechat.wx.pagination.impl.Page;
import com.wcfsy.wechat.wx.sys.dao.CouponDao;
import com.wcfsy.wechat.wx.util.StringUtil;

@Controller
@RequestMapping("/cms/coupon")
public class CouponController {


	@Resource
	private CouponDao couponDao;

	@RequestMapping({ "/view/page" })
	public String page() {
		return "coupon/coupon_list";
	}

	@RequestMapping({ "/view" })
	@ResponseBody
	public IPage<Coupon> view(int page, int rows) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("index", page);
		paramMap.put("size", rows);
		paramMap.put("limit", "limit");
		IPage<Coupon> page1 = new Page<Coupon>(couponDao.findByParam(paramMap),
				couponDao.count(paramMap), page, rows);
		List<Coupon> list = page1.getData();
		for (int i = 0; i < list.size() ; i++) {
			if(StringUtils.isNotEmpty(page1.getData().get(i).getUserName())){
				page1.getData().get(i).setUserName(StringUtil.decode(page1.getData().get(i).getUserName()));
			}
		}
		return page1;
	}

}
